package CfengMiddleWare.api.response;

import CfengMiddleWare.api.enums.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author Cfeng
 * @date 2022/9/13
 * 包装类型，T为返回的数据类型
 */

@Accessors(chain = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseResponse<T> {

    private StatusCode statusCode;

    private T data;

    private String errorMsg;

    public static <T> BaseResponse<T> ok(T data) {
        return new BaseResponse<T>().setData(data).setStatusCode(StatusCode.SUCCESS);
    }

    public static <T> BaseResponse<T> failed(String errorMsg) {
        return new BaseResponse<T>().setStatusCode(StatusCode.FAILED).setErrorMsg(errorMsg);
    }
}
